//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "FloatingRateBond.h"
using namespace Cephei::QL::Instruments::Bonds;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Times/Schedule.h>
#include <gen/QL/CashFlow.h>
#include <gen/QL/PricingEngine.h>
#include <gen/QL/Instruments/Bond.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
using namespace Cephei::QL::Instruments;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (UInt32 settlementDays, Double faceAmount, DateTime startDate, DateTime maturityDate, QL::Times::FrequencyEnum couponFrequency, Cephei::QL::Times::ICalendar^ calendar, Cephei::QL::Indexes::IIborIndex^ index, Cephei::QL::Times::IDayCounter^ accrualDayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ accrualConvention, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<UInt32>^ fixingDays, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ gearings, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ spreads, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ caps, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ floors, Microsoft::FSharp::Core::FSharpOption<Boolean>^ inArrears, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ stubDate, Microsoft::FSharp::Core::FSharpOption<QL::Times::DateGeneration::RuleEnum>^ rule, Microsoft::FSharp::Core::FSharpOption<Boolean>^ endOfMonth, Cephei::QL::IPricingEngine^ QL_Pricer) : CBond(CFloatingRateBond::typeid)
{
    CCalendar^ _Ccalendar;
    CIborIndex^ _Cindex;
    CDayCounter^ _CaccrualDayCounter;
    CoVector<Double>^ _Cgearings;
    CoVector<Double>^ _Cspreads;
    CoVector<Double>^ _Ccaps;
    CoVector<Double>^ _Cfloors;
    try
    {
#ifdef HANDLE
        _phFloatingRateBond = NULL;
#endif
        QuantLib::Natural _settlementDays = (QuantLib::Natural)ValueHelper::Convert (settlementDays);
        QuantLib::Real _faceAmount = (QuantLib::Real)ValueHelper::Convert (faceAmount);
        QuantLib::Date _startDate = (QuantLib::Date)ValueHelper::Convert (startDate);
        QuantLib::Date _maturityDate = (QuantLib::Date)ValueHelper::Convert (maturityDate);
        QuantLib::Frequency _couponFrequency = (QuantLib::Frequency)couponFrequency ;
        _Ccalendar = safe_cast<CCalendar^> (calendar);
        _Ccalendar->Lock();
        QuantLib::Calendar& _calendar = static_cast<QuantLib::Calendar&> (_Ccalendar->GetReference ()); 
        _Cindex = safe_cast<CIborIndex^> (index);
        _Cindex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _index = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_Cindex->GetShared ()); 
        _CaccrualDayCounter = safe_cast<CDayCounter^> (accrualDayCounter);
        _CaccrualDayCounter->Lock();
        QuantLib::DayCounter& _accrualDayCounter = static_cast<QuantLib::DayCounter&> (_CaccrualDayCounter->GetReference ()); 
        QuantLib::BusinessDayConvention _accrualConvention = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>::IsSome::get (accrualConvention) ? (QuantLib::BusinessDayConvention)accrualConvention->Value : QuantLib::BusinessDayConvention::Following); //10
        QuantLib::BusinessDayConvention _paymentConvention = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>::IsSome::get (paymentConvention) ? (QuantLib::BusinessDayConvention)paymentConvention->Value : QuantLib::BusinessDayConvention::Following); //10
        QuantLib::Natural _fixingDays = 
            (Microsoft::FSharp::Core::FSharpOption<UInt32>::IsSome::get (fixingDays) ? (QuantLib::Natural)ValueHelper::Convert (fixingDays->Value) : Null<QuantLib::Natural>()); //4
        CDoubleVector^ _NCgearings;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (gearings))
        {
            _Cgearings = safe_cast<CoVector<Double>^> (gearings->Value);
            _Cgearings->Lock();
            INativeVector<Double>^ _NCIgearings = _Cgearings->getFeature (NativeFeature::Value);
            _NCgearings = safe_cast<CDoubleVector^>(_NCIgearings);
        }
        std::vector<QuantLib::Real>& _gearings = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (gearings) ? static_cast<std::vector<QuantLib::Real>&> (_NCgearings->GetReference ()) : std::vector<QuantLib::Real>(1, 1.0)); //3
        CDoubleVector^ _NCspreads;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (spreads))
        {
            _Cspreads = safe_cast<CoVector<Double>^> (spreads->Value);
            _Cspreads->Lock();
            INativeVector<Double>^ _NCIspreads = _Cspreads->getFeature (NativeFeature::Value);
            _NCspreads = safe_cast<CDoubleVector^>(_NCIspreads);
        }
        std::vector<QuantLib::Spread>& _spreads = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (spreads) ? static_cast<std::vector<QuantLib::Spread>&> (_NCspreads->GetReference ()) : std::vector<QuantLib::Spread>(1, 0.0)); //3
        CDoubleVector^ _NCcaps;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (caps))
        {
            _Ccaps = safe_cast<CoVector<Double>^> (caps->Value);
            _Ccaps->Lock();
            INativeVector<Double>^ _NCIcaps = _Ccaps->getFeature (NativeFeature::Value);
            _NCcaps = safe_cast<CDoubleVector^>(_NCIcaps);
        }
        std::vector<QuantLib::Rate>& _caps = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (caps) ? static_cast<std::vector<QuantLib::Rate>&> (_NCcaps->GetReference ()) : std::vector<QuantLib::Rate>()); //3
        CDoubleVector^ _NCfloors;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (floors))
        {
            _Cfloors = safe_cast<CoVector<Double>^> (floors->Value);
            _Cfloors->Lock();
            INativeVector<Double>^ _NCIfloors = _Cfloors->getFeature (NativeFeature::Value);
            _NCfloors = safe_cast<CDoubleVector^>(_NCIfloors);
        }
        std::vector<QuantLib::Rate>& _floors = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (floors) ? static_cast<std::vector<QuantLib::Rate>&> (_NCfloors->GetReference ()) : std::vector<QuantLib::Rate>()); //3
        bool _inArrears = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (inArrears) ? (bool)ValueHelper::Convert (inArrears->Value) : false); //4
        QuantLib::Real _redemption = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (redemption) ? (QuantLib::Real)ValueHelper::Convert (redemption->Value) : 100.0); //4
        QuantLib::Date _issueDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (issueDate) ? (QuantLib::Date)ValueHelper::Convert (issueDate->Value) : QuantLib::Date()); //4
        QuantLib::Date _stubDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (stubDate) ? (QuantLib::Date)ValueHelper::Convert (stubDate->Value) : QuantLib::Date()); //4
        QuantLib::DateGeneration::Rule _rule = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::DateGeneration::RuleEnum>::IsSome::get (rule) ? (QuantLib::DateGeneration::Rule)rule->Value : QuantLib::DateGeneration::Rule::Backward); //10
        bool _endOfMonth = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (endOfMonth) ? (bool)ValueHelper::Convert (endOfMonth->Value) : false); //4
        _ppFloatingRateBond = new boost::shared_ptr<QuantLib::FloatingRateBond> (new QuantLib::FloatingRateBond ( _settlementDays,  _faceAmount,  _startDate,  _maturityDate,  _couponFrequency,  _calendar,  _index,  _accrualDayCounter,  _accrualConvention,  _paymentConvention,  _fixingDays,  _gearings,  _spreads,  _caps,  _floors,  _inArrears,  _redemption,  _issueDate,  _stubDate,  _rule,  _endOfMonth ));
        CPricingEngine^ _CQL_Pricer = safe_cast<CPricingEngine^> (QL_Pricer);
        boost::shared_ptr<QuantLib::PricingEngine>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_CQL_Pricer->GetShared ());
        (*_ppFloatingRateBond)->setPricingEngine (_QL_Pricer);
        SetBond (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFloatingRateBond));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ccalendar != nullptr) _Ccalendar->Unlock();
        if (_Cindex != nullptr) _Cindex->Unlock();
        if (_CaccrualDayCounter != nullptr) _CaccrualDayCounter->Unlock();
        if (_Cgearings != nullptr) _Cgearings->Unlock();
        if (_Cspreads != nullptr) _Cspreads->Unlock();
        if (_Ccaps != nullptr) _Ccaps->Unlock();
        if (_Cfloors != nullptr) _Cfloors->Unlock();
    }
}
Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (UInt32 settlementDays, Double faceAmount, Cephei::QL::Times::ISchedule^ schedule, Cephei::QL::Indexes::IIborIndex^ index, Cephei::QL::Times::IDayCounter^ accrualDayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<UInt32>^ fixingDays, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ gearings, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ spreads, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ caps, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ floors, Microsoft::FSharp::Core::FSharpOption<Boolean>^ inArrears, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Cephei::QL::IPricingEngine^ QL_Pricer) : CBond(CFloatingRateBond::typeid)
{
    CSchedule^ _Cschedule;
    CIborIndex^ _Cindex;
    CDayCounter^ _CaccrualDayCounter;
    CoVector<Double>^ _Cgearings;
    CoVector<Double>^ _Cspreads;
    CoVector<Double>^ _Ccaps;
    CoVector<Double>^ _Cfloors;
    try
    {
#ifdef HANDLE
        _phFloatingRateBond = NULL;
#endif
        QuantLib::Natural _settlementDays = (QuantLib::Natural)ValueHelper::Convert (settlementDays);
        QuantLib::Real _faceAmount = (QuantLib::Real)ValueHelper::Convert (faceAmount);
        _Cschedule = safe_cast<CSchedule^> (schedule);
        _Cschedule->Lock();
        QuantLib::Schedule& _schedule = static_cast<QuantLib::Schedule&> (_Cschedule->GetReference ()); 
        _Cindex = safe_cast<CIborIndex^> (index);
        _Cindex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _index = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_Cindex->GetShared ()); 
        _CaccrualDayCounter = safe_cast<CDayCounter^> (accrualDayCounter);
        _CaccrualDayCounter->Lock();
        QuantLib::DayCounter& _accrualDayCounter = static_cast<QuantLib::DayCounter&> (_CaccrualDayCounter->GetReference ()); 
        QuantLib::BusinessDayConvention _paymentConvention = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>::IsSome::get (paymentConvention) ? (QuantLib::BusinessDayConvention)paymentConvention->Value : QuantLib::BusinessDayConvention::Following); //10
        QuantLib::Natural _fixingDays = 
            (Microsoft::FSharp::Core::FSharpOption<UInt32>::IsSome::get (fixingDays) ? (QuantLib::Natural)ValueHelper::Convert (fixingDays->Value) : Null<QuantLib::Natural>()); //4
        CDoubleVector^ _NCgearings;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (gearings))
        {
            _Cgearings = safe_cast<CoVector<Double>^> (gearings->Value);
            _Cgearings->Lock();
            INativeVector<Double>^ _NCIgearings = _Cgearings->getFeature (NativeFeature::Value);
            _NCgearings = safe_cast<CDoubleVector^>(_NCIgearings);
        }
        std::vector<QuantLib::Real>& _gearings = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (gearings) ? static_cast<std::vector<QuantLib::Real>&> (_NCgearings->GetReference ()) : std::vector<QuantLib::Real>(1, 1.0)); //3
        CDoubleVector^ _NCspreads;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (spreads))
        {
            _Cspreads = safe_cast<CoVector<Double>^> (spreads->Value);
            _Cspreads->Lock();
            INativeVector<Double>^ _NCIspreads = _Cspreads->getFeature (NativeFeature::Value);
            _NCspreads = safe_cast<CDoubleVector^>(_NCIspreads);
        }
        std::vector<QuantLib::Spread>& _spreads = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (spreads) ? static_cast<std::vector<QuantLib::Spread>&> (_NCspreads->GetReference ()) : std::vector<QuantLib::Spread>(1, 0.0)); //3
        CDoubleVector^ _NCcaps;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (caps))
        {
            _Ccaps = safe_cast<CoVector<Double>^> (caps->Value);
            _Ccaps->Lock();
            INativeVector<Double>^ _NCIcaps = _Ccaps->getFeature (NativeFeature::Value);
            _NCcaps = safe_cast<CDoubleVector^>(_NCIcaps);
        }
        std::vector<QuantLib::Rate>& _caps = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (caps) ? static_cast<std::vector<QuantLib::Rate>&> (_NCcaps->GetReference ()) : std::vector<QuantLib::Rate>()); //3
        CDoubleVector^ _NCfloors;
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (floors))
        {
            _Cfloors = safe_cast<CoVector<Double>^> (floors->Value);
            _Cfloors->Lock();
            INativeVector<Double>^ _NCIfloors = _Cfloors->getFeature (NativeFeature::Value);
            _NCfloors = safe_cast<CDoubleVector^>(_NCIfloors);
        }
        std::vector<QuantLib::Rate>& _floors = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>::IsSome::get (floors) ? static_cast<std::vector<QuantLib::Rate>&> (_NCfloors->GetReference ()) : std::vector<QuantLib::Rate>()); //3
        bool _inArrears = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (inArrears) ? (bool)ValueHelper::Convert (inArrears->Value) : false); //4
        QuantLib::Real _redemption = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (redemption) ? (QuantLib::Real)ValueHelper::Convert (redemption->Value) : 100.0); //4
        QuantLib::Date _issueDate = 
            (Microsoft::FSharp::Core::FSharpOption<DateTime>::IsSome::get (issueDate) ? (QuantLib::Date)ValueHelper::Convert (issueDate->Value) : QuantLib::Date()); //4
        _ppFloatingRateBond = new boost::shared_ptr<QuantLib::FloatingRateBond> (new QuantLib::FloatingRateBond ( _settlementDays,  _faceAmount,  _schedule,  _index,  _accrualDayCounter,  _paymentConvention,  _fixingDays,  _gearings,  _spreads,  _caps,  _floors,  _inArrears,  _redemption,  _issueDate ));
        CPricingEngine^ _CQL_Pricer = safe_cast<CPricingEngine^> (QL_Pricer);
        boost::shared_ptr<QuantLib::PricingEngine>& _QL_Pricer = static_cast<boost::shared_ptr<QuantLib::PricingEngine>&> (_CQL_Pricer->GetShared ());
        (*_ppFloatingRateBond)->setPricingEngine (_QL_Pricer);
        SetBond (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFloatingRateBond));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cschedule != nullptr) _Cschedule->Unlock();
        if (_Cindex != nullptr) _Cindex->Unlock();
        if (_CaccrualDayCounter != nullptr) _CaccrualDayCounter->Unlock();
        if (_Cgearings != nullptr) _Cgearings->Unlock();
        if (_Cspreads != nullptr) _Cspreads->Unlock();
        if (_Ccaps != nullptr) _Ccaps->Unlock();
        if (_Cfloors != nullptr) _Cfloors->Unlock();
    }
}
Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (boost::shared_ptr<QuantLib::FloatingRateBond>& childNative, Object^ owner) : CBond(CFloatingRateBond::typeid)
{
#ifdef HANDLE
	_phFloatingRateBond = NULL;
#endif
	_ppFloatingRateBond = &childNative;
    _ppBond = new boost::shared_ptr<QuantLib::Bond> (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFloatingRateBond));
}
Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (QuantLib::FloatingRateBond& childNative, Object^ owner) : CBond(CFloatingRateBond::typeid)
{
#ifdef HANDLE
	_phFloatingRateBond = NULL;
#endif
	_ppFloatingRateBond = new boost::shared_ptr<QuantLib::FloatingRateBond> (&childNative);
    _ppBond = new boost::shared_ptr<QuantLib::Bond> (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFloatingRateBond));
    _FloatingRateBondOwner = owner;
    _BondOwner = owner;
}

Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (CFloatingRateBond^ copy) : CBond(CFloatingRateBond::typeid)
{
#ifdef HANDLE
	_phFloatingRateBond = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFloatingRateBond = new boost::shared_ptr<QuantLib::FloatingRateBond> (copy->GetShared());
        _ppBond = new boost::shared_ptr<QuantLib::Bond> (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFloatingRateBond));
    }
}
Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (System::Type^ t) : CBond(CFloatingRateBond::typeid)
{
#ifdef HANDLE
	_phFloatingRateBond = NULL;
#endif
	if (!t->IsSubclassOf(CFloatingRateBond::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (QuantLib::Handle<QuantLib::FloatingRateBond>& childNative, Object^ owner)  : CBond(CFloatingRateBond::typeid)
{
	_phFloatingRateBond = &childNative;
	_ppFloatingRateBond = &static_cast<boost::shared_ptr<QuantLib::FloatingRateBond>>(childNative.currentLink());
    _ppBond = new boost::shared_ptr<QuantLib::Bond> (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFloatingRateBond));
    _FloatingRateBondOwner = owner;
}
Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (QuantLib::Handle<QuantLib::FloatingRateBond> childNative)  : CBond(CFloatingRateBond::typeid)
{
	_phFloatingRateBond = &childNative;
	_ppFloatingRateBond = &static_cast<boost::shared_ptr<QuantLib::FloatingRateBond>>(childNative.currentLink());
    _ppBond = new boost::shared_ptr<QuantLib::Bond> (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFloatingRateBond));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::Bonds::CFloatingRateBond::CFloatingRateBond (QuantLib::FloatingRateBond childNative)  : CBond(CFloatingRateBond::typeid)
{
#ifdef HANDLE
	_phFloatingRateBond = NULL;
#endif
	_ppFloatingRateBond = new boost::shared_ptr<QuantLib::FloatingRateBond> (new QuantLib::FloatingRateBond (childNative));
    _ppBond = new boost::shared_ptr<QuantLib::Bond> (boost::dynamic_pointer_cast<QuantLib::Bond> (*_ppFloatingRateBond));
}
#endif

Cephei::QL::Instruments::Bonds::CFloatingRateBond::~CFloatingRateBond ()
{
    if (_ppFloatingRateBond != NULL)
    {
	    delete _ppFloatingRateBond;
        _ppFloatingRateBond = NULL;
    }
}
Cephei::QL::Instruments::Bonds::CFloatingRateBond::!CFloatingRateBond ()
{
    if (_ppFloatingRateBond != NULL)
    {
	    delete _ppFloatingRateBond;
    }
}
QuantLib::FloatingRateBond& Cephei::QL::Instruments::Bonds::CFloatingRateBond::GetReference ()
{
    if (_ppFloatingRateBond == NULL) throw gcnew NativeNullException ();
	return **_ppFloatingRateBond;
}
boost::shared_ptr<QuantLib::FloatingRateBond>& Cephei::QL::Instruments::Bonds::CFloatingRateBond::GetShared ()
{
    if (_ppFloatingRateBond == NULL) throw gcnew NativeNullException ();
	return *_ppFloatingRateBond;
}
QuantLib::FloatingRateBond* Cephei::QL::Instruments::Bonds::CFloatingRateBond::GetPointer ()
{
    if (_ppFloatingRateBond == NULL) throw gcnew NativeNullException ();
	return &**_ppFloatingRateBond;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FloatingRateBond>& Cephei::QL::Instruments::Bonds::CFloatingRateBond::GetHandle ()
{
	if (_phFloatingRateBond == NULL)
	{
		_phFloatingRateBond = new Handle<QuantLib::FloatingRateBond> (*_ppFloatingRateBond);
	}
	return *_phFloatingRateBond;
}
#endif
bool Cephei::QL::Instruments::Bonds::CFloatingRateBond::HasNative () 
{
	return (_ppFloatingRateBond != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::Bonds::IFloatingRateBond^ Cephei::QL::Instruments::Bonds::CFloatingRateBond_Factory::Create (UInt32 settlementDays, Double faceAmount, DateTime startDate, DateTime maturityDate, QL::Times::FrequencyEnum couponFrequency, Cephei::QL::Times::ICalendar^ calendar, Cephei::QL::Indexes::IIborIndex^ index, Cephei::QL::Times::IDayCounter^ accrualDayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ accrualConvention, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<UInt32>^ fixingDays, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ gearings, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ spreads, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ caps, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ floors, Microsoft::FSharp::Core::FSharpOption<Boolean>^ inArrears, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Microsoft::FSharp::Core::FSharpOption<DateTime>^ stubDate, Microsoft::FSharp::Core::FSharpOption<QL::Times::DateGeneration::RuleEnum>^ rule, Microsoft::FSharp::Core::FSharpOption<Boolean>^ endOfMonth, Cephei::QL::IPricingEngine^ QL_Pricer)
{
    return gcnew CFloatingRateBond ( settlementDays,  faceAmount,  startDate,  maturityDate,  couponFrequency,  calendar,  index,  accrualDayCounter,  accrualConvention,  paymentConvention,  fixingDays,  gearings,  spreads,  caps,  floors,  inArrears,  redemption,  issueDate,  stubDate,  rule,  endOfMonth,  QL_Pricer);
}
Cephei::QL::Instruments::Bonds::IFloatingRateBond^ Cephei::QL::Instruments::Bonds::CFloatingRateBond_Factory::Create (UInt32 settlementDays, Double faceAmount, Cephei::QL::Times::ISchedule^ schedule, Cephei::QL::Indexes::IIborIndex^ index, Cephei::QL::Times::IDayCounter^ accrualDayCounter, Microsoft::FSharp::Core::FSharpOption<QL::Times::BusinessDayConventionEnum>^ paymentConvention, Microsoft::FSharp::Core::FSharpOption<UInt32>^ fixingDays, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ gearings, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ spreads, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ caps, Microsoft::FSharp::Core::FSharpOption<Cephei::IVector<Double>^>^ floors, Microsoft::FSharp::Core::FSharpOption<Boolean>^ inArrears, Microsoft::FSharp::Core::FSharpOption<Double>^ redemption, Microsoft::FSharp::Core::FSharpOption<DateTime>^ issueDate, Cephei::QL::IPricingEngine^ QL_Pricer)
{
    return gcnew CFloatingRateBond ( settlementDays,  faceAmount,  schedule,  index,  accrualDayCounter,  paymentConvention,  fixingDays,  gearings,  spreads,  caps,  floors,  inArrears,  redemption,  issueDate,  QL_Pricer);
}
